package model.reservation.teacher;

import java.io.Serializable;
import java.util.ArrayList;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import model.Group;
import model.Groups;
import model.LectureRoom;
import model.LectureRooms;
import model.Time;
import model.Warning;

@XmlRootElement(name="subject")
public class Subject implements Serializable
{
	private static final long serialVersionUID = 555356982950492841L;

	private static int i = 0;
	
	@XmlAttribute
	private String id = "";
	
	@XmlElement
	private Time time;
	
	@XmlElement
	private String name;
	
	@XmlElement
	private String type;
	
	@XmlElement
	private Groups groups = new Groups();
	
	@XmlElement
	private LectureRooms lectureRooms = new LectureRooms();
	
	@XmlElement
	private Warning warning;
	
	public Subject() {}
	
	public Subject(Time time, String name, String type, Warning warning)
	{
		i++;
		this.id = i + "";
		this.time = time;
		this.name = name;
		this.type = type;
		this.warning = warning;
	}
	
	public Group createGroup(String name)
	{
		Group group = new Group(name);
		groups.groupsList.add(group);
		return group;
	}
	
	public LectureRoom createLectureRoom(String name)
	{
		LectureRoom lectureRoom = new LectureRoom(name);
		lectureRooms.lectureRoomsList.add(lectureRoom);
		return lectureRoom;
	}
	
	public String toString()
	{
		String groupsList = "";
		for (int i = 0; i < groups.groupsList.size(); i++)
		{
			groupsList += groups.groupsList.get(i);
			if(i < groups.groupsList.size() - 1)
				groupsList += "; ";
		}
		
		String lectureRoomList = "";
		for (int i = 0; i < lectureRooms.lectureRoomsList.size(); i++)
		{
			lectureRoomList += lectureRooms.lectureRoomsList.get(i);
			if(i < lectureRooms.lectureRoomsList.size() - 1)
				lectureRoomList += "; ";
		}
		
		return "Subject id(" + id + ") -> Time: " + time + " | Name: " + name + " | Type: " + type + " | Groups: " + groupsList + " | Lecture rooms: " + lectureRoomList + " | warning: " + warning;
	}

	public String getId()
	{
		return id;
	}

	public Time getTime()
	{
		return time;
	}

	public String getName()
	{
		return name;
	}

	public String getType()
	{
		return type;
	}
	
	public ArrayList<Group> getGroups()
	{
		return groups.groupsList;
	}

	public ArrayList<LectureRoom> getLectureRooms()
	{
		return lectureRooms.lectureRoomsList;
	}

	public Warning getWarning()
	{
		return warning;
	}
}
